package com.ygo.feihua.view;
import android.content.*;
import android.graphics.*;
import android.util.*;
import android.widget.*;
import com.ygo.feihua.*;
import java.util.*;
import android.widget.ImageView.*;
import android.view.*;
import cn.bmob.v3.datatype.*;

public class ShequMessageLayout extends LinearLayout
{
	private Context context;

	private Gongju gj;
	private AttributeSet attrs;
	public ShequMessageLayout(Context context,AttributeSet attrs){
		super(context,attrs);
		this.context=context;
		this.attrs=attrs;
		//设置LinearLayout水平或垂直
        setOrientation(LinearLayout.VERTICAL);
		//LinearLayout背景
        setBackgroundColor(Color.TRANSPARENT);
		gj=Gongju.getdx(context);
	}
	
	public void setMessage(List<TieziMessage> ltm){
		removeAllViews();
		for(TieziMessage tm:ltm){
			if(tm.getImage()!=null){
				showImage(tm.getImage());
			}
			if(!tm.getMessage().equals("")){
				showTv(tm.getMessage());
			}
			}
	}
	
	public  int dpToPx(int dp){
        float density = getContext().getResources().getDisplayMetrics().density;
        return (int)(dp * density + 0.5f);
    }
	
	private void showImage(final BmobFile bf){
		final ImageView iv=new ImageView(context);
		LayoutParams lp= new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		iv.setScaleType(ScaleType.FIT_CENTER);
		lp.setMargins(0,10,0,10);
		iv.setLayoutParams(lp);
		iv.setScaleType(ImageView.ScaleType.FIT_XY);
		gj.tuxian(bf,iv);
		iv.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					Intent intent1 =new Intent(context,ImageXiangxi.class);
					intent1.putExtra("uri",bf.getFileUrl());
					context.startActivity(intent1);
					// TODO: Implement this method
				}
			});
		addView(iv);
		}
		
	private void showTv(String s){
		//TextView tv=new TextView(context);
		LiaotianMessageLayout lm=new LiaotianMessageLayout(context,attrs);
		lm.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		lm.setMessage(s);
		/*tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		tv.setTextSize(18);
		tv.setText(s);
		tv.setTextColor(Color.BLACK);
		tv.setBackgroundColor(Color.TRANSPARENT);*/
		addView(lm);
	}
	
}
